package com.peng.dian.controller;

import com.peng.dian.mapper.UserLogin;
import com.peng.dian.pojo.User1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Autowired
    private UserLogin userLogin;

    @RequestMapping("/user/login")
    public String login(@RequestParam("username") String username, @RequestParam("password") String password, Model model,
                        HttpSession httpSession){
        User1 user = userLogin.queryUserById(username);
      if (user!=null && user.getPassword().equals(password)){
              httpSession.setAttribute("Username","Username");
              httpSession.setAttribute("pengge","欢迎玩家"+username+"登录账号！");
              return "redirect:/main.html";

      }
      else {
          model.addAttribute("msg","用户名或者密码不正确");
          return "index";
      }
    }
    @RequestMapping("/user/layout")
    public String logout(HttpSession session){
        session.invalidate();
        return "redirect:/user/login";
    }
}
